<html>

<head>
<title> Calculator </title>
</head>

<body>

<h1> Calculator </h1>
<p1> Enter an expression </p1>


<form action="calculator.php" method="get">
<input type="text" name="expr" />
<input type="submit" />
</form>

<?php

$expr = $_GET["expr"];

if(preg_match("@[aA-zZ]@", $expr))
{
	echo "Error: Invalid Expression" . "<br />";
}
elseif(preg_match("@\/0@",$expr))
{
	echo "Error: Division by Zero" . "<br />";
}
elseif(preg_match("@\`|\~|\!|\%|\^|\&|\(|\)|\:|\;|\_|\=|\,|\.|\<|\>|\?@",$expr))
{
	echo "Error: Invalid Expression" . "<br />";
}
else
{
	echo $expr . " = " . eval("return $expr;");
}

?>

</body>
</html>
